#ifndef __IO_MANAGER_H__
#define __IO_MANAGER_H__

#include <stdlib.h>

#include "TH1D.h"
#include "TFile.h"
#include "RooPlot.h"
#include "AnalysisException.h"

#include "TList.h"
#include "TObject.h"
#include "TTree.h"
using namespace RooFit;

class IOmanager
{
    public:
        static int ET_VALUE[15];
        static int ETA_VALUE[20];
    public:
        static void    openInput (TString filename);
        static void    closeInput();
        static void    openOutput (TString name, TString mode="recreate");
        static void    closeOutput();
        static void    save(TObject* t);
        static void    savePlot(RooPlot* p, bool log, TString dir1,TString dir2,TString dir3,TString dir4,TString dir5,TString dir6);
        static void    drawAndSave(RooPlot *p, TString filename, bool log=false);
        static void    readAxisValuesFromFile(TString filename,int histoNumber=0);
    public:
        static int     getETbin(int val);
        static TH1D*   getProjectionZ(int        o, int eta_min, int eta_max, int bin_min, int bin_max);
        static TH1D*   getProjectionZ(TString name, int eta_min, int eta_max, int bin_min, int bin_max);
        static TTree*  getNtuple(TString filename);
        static IOmanager& instance();
    private:
        IOmanager();
        ~IOmanager();
        static IOmanager* _instance; // Singleton

        static TFile* input;
        static TFile* output;
    public:
        static TTree* ntuple;
        static int    n_PROBE,n_LOOSE,n_MEDIUM,n_TIGHT;
        static int    n_isData,n_version;
        static int    n_method,n_sig_templ,n_eta_min,n_eta_max;
        static int    n_effic_method;
        static int    n_isEM,n_bgd_templ,n_isol_th,n_ETmin,n_ETmax;
        static double    n_effic_test_result;
        static double n_nsig_probe,n_nsig_probe_err,n_nsig_sel,n_nsig_sel_err;
        static double n_nbgd_probe,n_nbgd_probe_err,n_nbgd_sel,n_nbgd_sel_err;
        static double n_fit_chi_sq;
        static double n_efficiency,n_efficiency_err;
};

#endif
